package com.bdqn.t313.service;

import com.bdqn.t313.dao.UserDao;
import com.bdqn.t313.dao.UserDaoImpl;
import com.bdqn.t313.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service("userService")
public class UserServiceImpl implements UserService {

    //传统获取Bean的实例
    //private UserDao userDao = new UserDaoImpl();

    //使用setter方法进行userDao的注入
    //Autowired：默认使用按类型(byType)进行自动装配，如果需要按名称(byName)，
    //需要搭配@Qualifier注解一起使用
    @Autowired
    @Qualifier("userDao2")
    //@Resource：如果不指定name和type属性时，默认按照byName进行自动装配
    private UserDao userDao;

    /*public UserServiceImpl(UserDao userDao) {
        this.userDao = userDao;
    }*/

    /*public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }*/

    @Override
    public int save(User user) {

        return userDao.save(user);
    }
}
